package com.base.web.socket.utils;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.base.common.sys.entity.SysUserEntity;
import com.base.common.sys.service.SysUserService;

@Component
public class SysUserUtils {

	private static SysUserUtils sysUserUtils;

	public SysUserUtils(){
		sysUserUtils = this;
	}
	
	@Autowired
	private SysUserService sysUserService;
	
	@PostConstruct
	public void uptAllSysUserStatus() {
		SysUserEntity entity = new SysUserEntity();
		entity.setStatus(0);
		sysUserService.updateByEntity(entity);
	}
	
	/** 更新用户在线状态 */
	public static void uptSysUserStatus(Integer status, String userId) {
		SysUserEntity user = sysUserUtils.sysUserService.findById(Integer.valueOf(userId));
		user.setStatus(status);
		sysUserUtils.sysUserService.updateById(user);
		try {
			Thread.sleep(200); //先更新了好友状态-再让前端刷新列表
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
